using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace NutriStat
{
    // Code here was derived from that found on http://msdn.microsoft.com/en-us/library/ms229644.aspx
    class IntegerTextBox : TextBox
    {
        bool allowSpace = false;

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);

            // We want to make sure we get the right separator! Epi 3 has a serious problem when
            // non-US users try to do decimal math, because it always assumes the period is the
            // separator. We don't want to fall into this trap.
            NumberFormatInfo numberFormatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
            string decimalSeparator = numberFormatInfo.NumberDecimalSeparator;            
            string negativeSign = numberFormatInfo.NegativeSign;    // we don't technically need these for the input boxes, so I may remove them later

            string keyInput = e.KeyChar.ToString();

            if (Char.IsDigit(e.KeyChar))
            {
                // Digits are okay
            }            
            else if (e.KeyChar == '\b')
            {
                // Backspace key is OK
            }
            //    else if ((ModifierKeys & (Keys.Control | Keys.Alt)) != 0)
            //    {
            //     // Let the edit control handle control and alt key combinations
            //    }            
            else
            {
                // Consume this invalid key
                e.Handled = true;                
            }
        }

        public int IntValue
        {
            get
            {
                return Int32.Parse(this.Text);
            }
        }

        public decimal DecimalValue
        {
            get
            {
                return Decimal.Parse(this.Text);
            }
        }

        public bool AllowSpace
        {
            set
            {
                this.allowSpace = value;
            }

            get
            {
                return this.allowSpace;
            }
        }


    }
}